﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.MapInfo.BLL;

public partial class MapInfo_DepartmentKinds : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.DptDepartment.SelectedIndexChanged += new EventHandler(DptDepartment_SelectedIndexChanged);
        if (!IsPostBack)
        {
            
            Bind();
            DptDepartment_SelectedIndexChanged(this.DptDepartment, new EventArgs());
        }
            
    }

    public void DptDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.LbxAllDepartment.DataSource = Yipusoft.Account.BLL.Department.GetList("Left(DepartmentID,4)='"+DptDepartment.SelectedValue.Substring(0,4)+"'");
        this.LbxAllDepartment.DataTextField = "FullName";
        this.LbxAllDepartment.DataValueField = "DepartmentID";
        this.LbxAllDepartment.DataBind();
        this.LbxCenter.DataSource = DepartmentKinds.GetList("Left(DepartmentID,4)='" + DptDepartment.SelectedValue.Substring(0, 4) + "'");
        this.LbxCenter.DataTextField = "DepartmentName";
        this.LbxCenter.DataValueField = "DepartmentID";
        this.LbxCenter.DataBind();
    }

    private void Bind()
    {
        this.DptDepartment.DataSource = Yipusoft.Account.BLL.Department.GetList("Right(DepartmentID,2)='00' Order By DepartmentID");
        this.DptDepartment.DataTextField = "FullName";
        this.DptDepartment.DataValueField = "DepartmentID";
        this.DptDepartment.DataBind();

    }
    protected void BtnSelect_Click(object sender, EventArgs e)
    {
        if (LbxAllDepartment.SelectedIndex>=0)
        {
            try
            {
                DepartmentKinds.Add(LbxAllDepartment.SelectedItem.Text, LbxAllDepartment.SelectedValue);
                DptDepartment_SelectedIndexChanged(this.DptDepartment, new EventArgs());
            }
            catch { };
        }
    }
    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        if (LbxCenter.SelectedIndex >= 0)
        {
            DepartmentKinds.Delete(LbxCenter.SelectedValue);
            DptDepartment_SelectedIndexChanged(this.DptDepartment, new EventArgs());

        }
    }
}
